package com.jm.offer.easy;

import java.util.Arrays;
import java.util.HashSet;

/**
 * @Description https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/
 * @date 2022/4/1 7:45
 */
public class _03数组中重复的数字 {
    public static void main(String[] args) {
        int[] arr = new int[]{6, 3, 1, 2, 3, 5, 6};
        System.out.println(repeatOfArr(arr));
    }

    public static int repeatOfArr(int[] arr){
        HashSet<Integer> set = new HashSet<>();
        for (int i : arr) {
            if (!set.add(i)){
                return i;
            }
        }
        return -1;
    }
}
